package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QtChapter;
import com.ruoyi.system.service.IQtChapterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节管理Controller
 * 
 * @author zqq
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/chapter/chapter")
public class QtChapterController extends BaseController
{
    @Autowired
    private IQtChapterService qtChapterService;

    /**
     * 查询章节管理列表
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtChapter qtChapter)
    {
        startPage();
        List<QtChapter> list = qtChapterService.selectQtChapterList(qtChapter);
        return getDataTable(list);
    }

    /**
     * 导出章节管理列表
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:export')")
    @Log(title = "章节管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtChapter qtChapter)
    {
        List<QtChapter> list = qtChapterService.selectQtChapterList(qtChapter);
        ExcelUtil<QtChapter> util = new ExcelUtil<QtChapter>(QtChapter.class);
        return util.exportExcel(list, "章节管理数据");
    }

    /**
     * 获取章节管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:query')")
    @GetMapping(value = "/{chapterId}")
    public AjaxResult getInfo(@PathVariable("chapterId") String chapterId)
    {
        return AjaxResult.success(qtChapterService.selectQtChapterByChapterId(chapterId));
    }

    /**
     * 新增章节管理
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:add')")
    @Log(title = "章节管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtChapter qtChapter)
    {
        return toAjax(qtChapterService.insertQtChapter(qtChapter));
    }

    /**
     * 修改章节管理
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:edit')")
    @Log(title = "章节管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtChapter qtChapter)
    {
        return toAjax(qtChapterService.updateQtChapter(qtChapter));
    }

    /**
     * 删除章节管理
     */
    @PreAuthorize("@ss.hasPermi('chapter:chapter:remove')")
    @Log(title = "章节管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chapterIds}")
    public AjaxResult remove(@PathVariable String[] chapterIds)
    {
        return toAjax(qtChapterService.deleteQtChapterByChapterIds(chapterIds));
    }
}
